import { createRouter, createWebHistory } from 'vue-router'
import store from '../assets/js/store.js'

const routes = [{
    path: '/',
    name: 'Home',
    component: () => import('../views/home.vue'),
  },{
	  path:'/chat/:sessionId',
	  name: 'chat',
	  component: () => import('../views/ai/chatAi.vue'),
	  needLogin: true,
	  aiShow: false,
  },{
	  path: '/ai_session',
	  name: 'sessionList',
	  component: () => import('../views/ai/sessionList.vue'),
	  needLogin: true,
	  tabbar: false,
	  aiShow: false
  },{
	  path:'/login',
	  name:'login',
	  component: () => import('../views/user/login.vue'),
	  tabbar: false,
	  aiShow: false,
  },{
	  path:'/register',
	  name:'register',
	  component: () => import('../views/user/register.vue'),
	  tabbar: false,
	  aiShow: false,
  },{
	  path:'/city',
	  name:'city',
	  component: () => import('../views/city/homeCity.vue'),
	  tabbar: false,
  },{
	  path: '/article_details/:type/:id',
	  name: 'articleDetails',
	  component: () => import('../views/community/articleDetails.vue'),
	  needLogin: true,
  },
]


const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes
});

router.beforeEach((to, from, next) => {
	for(let i = 0; i < routes.length; i++){
		if(to.fullPath == routes[i].path){
			if(routes[i].needLogin && !localStorage.getItem("travel")) router.push({path: '/login'});
			store.state.tabbarShow = routes[i].tabbar != undefined ? false : true;
			store.state.aiShow = routes[i].aiShow != undefined ? false : true;
		}
	}
	next();
})

export default router
